	  fbConnected = false;
	  
	  window.fbAsyncInit = function() {
	  FB.init({
		appId      : '236395369863459',
		status     : true, // check login status
		cookie     : true, // enable cookies to allow the server to access the session
		xfbml      : true  // parse XFBML
	  });
	 
	  FB.Event.subscribe('auth.authResponseChange', function(response) {
		if (response.status === 'connected') {
		  //testAPI();
			//affiche du button logout
			fbConnected = true;
			$("#fb-root").hide();
			FB.api('/me', function(response) 
			{
				$("#userName").html('<span class="h4" style="margin-right:10px; color:white;">'+response.name+'</span><button type="button" class="btn btn-sm btn-danger" onClick="fbLogout();">Logout</button>');
				if( typeof user === 'undefined' ){
					//alert("METH: FB.EVENT: Cannot init API Channel : User not defined!");
				}else{ 
					user = new User(response.id, response.name);
					//Get new GAE API Channel token
					newChannelToken(user);
				}
			}); 
		} else if (response.status === 'not_authorized') {
		  FB.login();
		} else {
		  FB.login();
		}
	  });
	  };

	  function Facebook_login(){
		FB.getLoginStatus(function(response) {
			if (response.status === 'connected') {
			  //testAPI();
				//affiche du button logout
				fbConnected = true;
				alert("fb connected");
				$("#fb-root").hide();
				FB.api('/me', function(response) 
				{
					$("#userName").html('<span class="h4" style="margin-right:10px; color:white;">'+response.name+'</span><button type="button" class="btn btn-sm btn-danger" onClick="fbLogout();">Logout</button>');
				}); 
			} else if (response.status === 'not_authorized') {
			  FB.login();
			} else {
			  FB.login();
			}			
		});
	  }
	  
	function fbLogout(){
		FB.logout(function(response) {
			window.location.reload();
		});
	}
	  
	  // Load the SDK asynchronously
	  (function(d){
	   var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
	   if (d.getElementById(id)) {return;}
	   js = d.createElement('script'); js.id = id; js.async = true;
	   js.src = "//connect.facebook.net/en_US/all.js";
	   ref.parentNode.insertBefore(js, ref);
	  }(document));
	  
	  // Here we run a very simple test of the Graph API after login is successful. 
	  // This testAPI() function is only called in those cases. 
	  /*function testAPI() {
		console.log('Welcome!  Fetching your information.... ');
		FB.api('/me', function(response) {
		  console.log('Good to see you, ' + response.name + '.');
		});
	  }*/	